<?php
include ('../../includes/global.php');
include ('../global.php');
include ("../power.php");
include ("../clas/ext.php");
$dbcfg=Sys::Gp(array('dbcfg','sevenel'));
$donotrender = array('htmleditor','fckeditor','password','hidden');

error_reporting(0);

/**
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * 这个脚本专门用来读取数据
 * $_GET['table'] 表名
 * $_GET['con'] 条件
 * 如：getCombo.php?table=test&con[del]=1&con[id]=5
 */

foreach($_REQUEST['con'] as $k=>$v){
    $con .= " and {$k}='{$v}'";
}


/**
 * 材料搜索用
 */
if ($_POST['searchKeys']) {
    $_searchFields = explode(',',$_POST['searchKeys']);
    $sql_tmp = array();
    foreach($_searchFields as $v){
        $sql_tmp[] = "{$v} like '%{$_POST['key']}%' ";
    }
    $sql_tmp = implode(' or ', $sql_tmp);
    $con .= "and ({$sql_tmp})";
}
if($_POST['type']){
    $con .= " and type='{$_POST['type']}'";
}

/**
 * 分页
 */
if($_POST['limit'] != ''){
    $limit = " limit {$_POST['start']},{$_POST['limit']}";
}
$d = Dgs($_REQUEST['table']," del!=1 {$con} {$limit}");
$total_num = mysql_fetch_array(mysql_query("select count(*) as n from se_{$_REQUEST['table']} where del!=1 {$con}"));

//转义
if(!empty($_REQUEST['combo'])){
    foreach($d as $k => &$v){
        $tmp = Dga($_REQUEST['combo']['con_table'],"{$_REQUEST['combo']['con_field']}='{$v[$_REQUEST['combo']['con_val_field']]}'");
        $v['old_field'] = $v[$_REQUEST['combo']['field']];
        $v[$_REQUEST['combo']['field']] = $tmp[$_REQUEST['combo']['val']];
    }
}

$r['data'] = $d;
$r['total'] = $total_num[0];

echo json_encode($r);

